package controller

import (
	"gitee.com/song-yao-shun/MQH/model"
	"gitee.com/song-yao-shun/MQH/response"
	"gitee.com/song-yao-shun/MQH/respository"
	"gitee.com/song-yao-shun/MQH/vo"
	"github.com/gin-gonic/gin"
)

type IDictController interface {
	RestController
}

type DictController struct {
	DictRty respository.DictRepository
}

func (d DictController) Create(ctx *gin.Context) {
	// 接收参数
	var voreq vo.CreateDictRequest
	if err := ctx.ShouldBind(&voreq); err != nil {
		response.Fail(ctx, nil, "数据验证错误！")
		return
	}

	// 创建 page
	cstruct := model.Dict{
		Key: 	voreq.Key,
		Name: 	voreq.Name,
		Type: 	voreq.Type,
	}

	cId, err := d.DictRty.Create(cstruct)
	if err != nil {
		response.Fail(ctx, nil, "新建失败！")
		return
	}

	// 返回
	response.Success(ctx, gin.H{"data":cId}, "新建成功！")
}

func (d DictController) Update(ctx *gin.Context) {
	panic("implement me")
}

func (d DictController) Show(ctx *gin.Context) {
	panic("implement me")
}

func (d DictController) Delete(ctx *gin.Context) {
	panic("implement me")
}

func (d DictController) List(ctx *gin.Context) {

	// 接收参数
	var voList vo.DictList
	if err := ctx.ShouldBind(&voList); err != nil {
		response.Fail(ctx, nil, "数据验证错误，请检查提交的内容！")
		return
	}

	structs, total := d.DictRty.List(voList)

	//if fctList.SelectType != ""{
	//	response.Success(ctx, gin.H{"data":dto.ToFctDto(fullFcts), "total":total}, "查询列表成功。")
	//	return
	//}

	response.Success(ctx, gin.H{"data":structs, "total":total}, "查询列表成功。")
}

func NewDictController() IDictController{
	return DictController{DictRty: respository.NewDictRepository()}
}